﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace PocketΦάρμακα
{
	public partial class TextBar : UserControl
	{
		public TextBar()
		{
			InitializeComponent();
		}

		protected override void OnResize(EventArgs e)
		{
			base.OnResize(e);
			pictureButtonGo.Height = textBox.Height;
			pictureButtonGo.Width = textBox.Height;
			pictureButtonClear.Size = pictureButtonGo.Size;
			Height = textBox.Height;
			textBox.Width = Width - (Height *2) +2;
			pictureButtonGo.Left = Width - pictureButtonGo.Width;
			pictureButtonClear.Left = Width - (pictureButtonGo.Width * 2) + 1;
		}

		private void textBox_TextChanged(object sender, EventArgs e)
		{
			pictureButtonGo.Enabled = (textBox.Text != "");
			pictureButtonClear.Enabled = (textBox.Text != "");
			OnTextChanged(e);
		}

		/// <summary>
		/// Only here so that it shows up in the property panel.
		/// </summary>
		public override string Text
		{
			get
			{
				return textBox.Text;
			}
			set
			{
				textBox.Text = value;
			}
		}

		public event EventHandler GoPressed;
		protected virtual void OnGoPressed(System.EventArgs e)
		{
			if (GoPressed != null)
				GoPressed(this, e);
		}
		public event EventHandler ClearPressed;
		protected virtual void OnClearPressed(System.EventArgs e)
		{
			if (ClearPressed != null)
				ClearPressed(this, e);
		}

		private void pictureButtonGo_Click(object sender, EventArgs e)
		{
			pictureButtonGo.Enabled = false;
			textBox.ReadOnly = true;
			OnGoPressed(e);
		}

		private void pictureButtonClear_Click(object sender, EventArgs e)
		{
			textBox.Text = "";
			textBox.ReadOnly = false;
			OnClearPressed(e);
		}
	}
}
